package com.wnhz.work.yz.fragment.video;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.base.BaseFragment;
import com.wnhz.work.yz.base.BaseRVAdapter;
import com.wnhz.work.yz.base.BaseViewHolder;
import com.wnhz.work.yz.bean.VideoBean;
import com.wnhz.work.yz.utils.DisplayUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * ---安装视频
 */
public class InstallFragment extends BaseFragment {
    private View view;
    private RecyclerView my_recycler;
    private BaseRVAdapter<VideoBean> videoAdapter;
    private List<VideoBean> beanList = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_install, container, false);
        initData();
        initView();
        return view;
    }

    private void initData() {
        for (int i = 0; i < 2; i++) {
            VideoBean bean = new VideoBean();
            beanList.add(bean);
        }
    }

    private void initView() {
        my_recycler = (RecyclerView) view.findViewById(R.id.my_recycler);


        videoAdapter = new BaseRVAdapter<VideoBean>(getActivity(), beanList) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.frag_video_item;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {
                switch (position % 2) {
                    case 0:
                        holder.itemView.setPadding(0, DisplayUtil.px2dp(getActivity(), 48), DisplayUtil.px2dp(getActivity(), 24), 0);
                        break;

                    case 1:
                        holder.itemView.setPadding(DisplayUtil.px2dp(getActivity(), 24), DisplayUtil.px2dp(getActivity(), 48), 0, 0);
                        break;

                    default:
                        break;
                }

            }
        };
        my_recycler.setLayoutManager(new GridLayoutManager(getActivity(), 2));
//        my_recycler.addItemDecoration(new RecycleViewDivider(getContext(), LinearLayout.HORIZONTAL,R.drawable.line_shape));
        my_recycler.setAdapter(videoAdapter);
    }

}
